package com.bluesky.javawebbrowser.domain.html.tags.form;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import com.bluesky.common.TreeNode;
import com.bluesky.javawebbrowser.domain.html.tags.Tag;
import com.bluesky.javawebbrowser.domain.html.tags.TagType;
import com.bluesky.javawebbrowser.domain.html.tags.TextBlock;
import com.bluesky.javawebbrowser.domain.html.tags.form.FormElement;

public class TextArea extends Tag implements FormElement {

	public String getName() {
		return (String) attributes.get("name");
	}

	public void setName(String name) {

		attributes.put("name", name);
	}

	public String getText() {
		return getBody();
	}

	public void setText(String text) {
		setBody(text);
		Tag t = new TextBlock(text);
		
		removeAllChildren();
		addChild(t);
	}

	public TextArea() {
		super(TagType.TEXTAREA);
	}

	public TextArea(Tag tag) {
		super(TagType.TEXTAREA);

		copy(tag);
	}

	@Override
	public String getHttpValue() {

		return getText();
	}

	@Override
	public void setHttpValue(String value) {
		setText(value);
	}

	public Integer getCols() {
		String scols = (String) getAttribute("cols");
		if (scols == null)
			return null;
		else
			return Integer.valueOf(scols);
	}

	public void setCols(Integer cols) {
		if (cols == null)
			removeAttribute("cols");
		else
			setAttribute("cols", String.valueOf(cols));
	}

	public Integer getRows() {
		String s = (String) getAttribute("rows");
		if (s == null)
			return null;
		else
			return Integer.valueOf(s);
	}

	public void setRows(Integer rows) {

		if (rows == null)
			removeAttribute("rows");
		else
			setAttribute("rows", String.valueOf(rows));
	}

}
